{% extends "member/layout.html" %}

{% block title %}我的审批记录{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <!-- 页面标题和操作按钮 -->
        <div class="d-flex justify-content-between align-items-center mb-4">
            <div>
                <h3 class="fw-bold text-primary mb-1">
                    <i class="fas fa-clipboard-check me-2"></i>我的审批记录
                </h3>
                <p class="text-muted mb-0">查看您提交的所有审批申请状态和历史记录</p>
            </div>
            <a href="{{ url_for('member.jira.list_projects') }}" class="btn btn-primary">
                <i class="fas fa-folder-open me-2"></i>从项目提交
            </a>
        </div>

        <!-- 统计卡片 -->
        <div class="row mb-4">
            <div class="col-md-3 mb-3">
                <div class="card dashboard-card border-0 h-100">
                    <div class="card-body">
                        <div class="d-flex align-items-center">
                            <div class="flex-shrink-0">
                                <div class="stat-icon bg-primary bg-opacity-10 text-primary rounded-circle p-3">
                                    <i class="fas fa-paper-plane fs-4"></i>
                                </div>
                            </div>
                            <div class="flex-grow-1 ms-3">
                                <h5 class="card-title text-muted mb-1">全部审批</h5>
                                <h3 class="stat-number mb-0">{{ approvals|length }}</h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-3 mb-3">
                <div class="card dashboard-card border-0 h-100">
                    <div class="card-body">
                        <div class="d-flex align-items-center">
                            <div class="flex-shrink-0">
                                <div class="stat-icon bg-warning bg-opacity-10 text-warning rounded-circle p-3">
                                    <i class="fas fa-clock fs-4"></i>
                                </div>
                            </div>
                            <div class="flex-grow-1 ms-3">
                                <h5 class="card-title text-muted mb-1">待审批</h5>
                                <h3 class="stat-number mb-0">{{ approvals|selectattr('status', 'equalto', 'pending')|list|length }}</h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-3 mb-3">
                <div class="card dashboard-card border-0 h-100">
                    <div class="card-body">
                        <div class="d-flex align-items-center">
                            <div class="flex-shrink-0">
                                <div class="stat-icon bg-success bg-opacity-10 text-success rounded-circle p-3">
                                    <i class="fas fa-check-circle fs-4"></i>
                                </div>
                            </div>
                            <div class="flex-grow-1 ms-3">
                                <h5 class="card-title text-muted mb-1">已通过</h5>
                                <h3 class="stat-number mb-0">{{ approvals|selectattr('status', 'equalto', 'approved')|list|length }}</h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-3 mb-3">
                <div class="card dashboard-card border-0 h-100">
                    <div class="card-body">
                        <div class="d-flex align-items-center">
                            <div class="flex-shrink-0">
                                <div class="stat-icon bg-danger bg-opacity-10 text-danger rounded-circle p-3">
                                    <i class="fas fa-times-circle fs-4"></i>
                                </div>
                            </div>
                            <div class="flex-grow-1 ms-3">
                                <h5 class="card-title text-muted mb-1">已拒绝</h5>
                                <h3 class="stat-number mb-0">{{ approvals|selectattr('status', 'equalto', 'rejected')|list|length }}</h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 审批记录表格 -->
        <div class="card dashboard-card border-0">
            <div class="card-header bg-transparent border-0 pb-0">
                <h5 class="mb-0 fw-bold text-dark">
                    <i class="fas fa-list me-2"></i>审批记录列表
                </h5>
            </div>
            <div class="card-body">
                {% if approvals %}
                <div class="table-responsive">
                    <table class="table table-hover align-middle">
                        <thead class="table-light">
                            <tr>
                                <th scope="col" class="ps-4">项目信息</th>
                                <th scope="col">审批类型</th>
                                <th scope="col">提交时间</th>
                                <th scope="col">状态</th>
                                <th scope="col" class="text-end pe-4">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for approval in approvals %}
                            <tr class="approval-row">
                                <td class="ps-4">
                                    <div class="d-flex align-items-center">
                                        <div class="flex-shrink-0">
                                            <div class="project-icon bg-primary bg-opacity-10 text-primary rounded p-2 me-3">
                                                <i class="fas fa-folder-open"></i>
                                            </div>
                                        </div>
                                        <div class="flex-grow-1">
                                            <h6 class="mb-1 fw-bold">{{ approval.project.name }}</h6>
                                            <p class="text-muted small mb-0">ID: {{ approval.id }}</p>
                                        </div>
                                    </div>
                                </td>
                                <td>
                                    <span class="badge bg-light text-dark">
                                        <i class="fas {% if approval.project_id %}fa-project-diagram{% else %}fa-tasks{% endif %} me-1"></i>
                                        {{ '项目审批' if approval.project_id else '常规审批' }}
                                    </span>
                                </td>
                                <td>
                                    <div class="d-flex flex-column">
                                        <span class="fw-medium">{{ approval.created_at.strftime('%Y-%m-%d') }}</span>
                                        <small class="text-muted">{{ approval.created_at.strftime('%H:%M') }}</small>
                                    </div>
                                </td>
                                <td>
                                    {% if approval.status == 'approved' %}
                                    <span class="badge bg-success bg-opacity-10 text-success border border-success border-opacity-25 rounded-pill px-3 py-2">
                                        <i class="fas fa-check-circle me-1"></i>已通过
                                    </span>
                                    {% elif approval.status == 'pending' %}
                                    <span class="badge bg-warning bg-opacity-10 text-warning border border-warning border-opacity-25 rounded-pill px-3 py-2">
                                        <i class="fas fa-clock me-1"></i>待审批
                                    </span>
                                    {% else %}
                                    <span class="badge bg-danger bg-opacity-10 text-danger border border-danger border-opacity-25 rounded-pill px-3 py-2">
                                        <i class="fas fa-times-circle me-1"></i>已拒绝
                                    </span>
                                    {% endif %}
                                </td>
                                <td class="text-end pe-4">
                                    {% if approval.status == 'pending' %}
                                    <span class="text-muted small">等待审批中</span>
                                    {% else %}
                                    <a href="{{ url_for('member.jira.project_detail', project_id=approval.project_id) }}"
                                       class="btn btn-sm btn-outline-primary">
                                        <i class="fas fa-eye me-1"></i>查看详情
                                    </a>
                                    {% endif %}
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                {% else %}
                <div class="text-center py-5">
                    <div class="mb-4">
                        <i class="fas fa-clipboard-list text-muted" style="font-size: 4rem;"></i>
                    </div>
                    <h5 class="text-muted mb-3">暂无审批记录</h5>
                    <p class="text-muted mb-4">您还没有提交任何审批申请，点击下方按钮创建第一个审批</p>
                    <a href="{{ url_for('member.jira.list_projects') }}" class="btn btn-primary">
                        <i class="fas fa-folder-open me-2"></i>从项目提交
                    </a>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<style>
.approval-row {
    transition: all 0.2s ease;
}

.approval-row:hover {
    background-color: rgba(67, 97, 238, 0.03);
    transform: translateY(-1px);
}

.project-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.table th {
    font-weight: 600;
    color: #495057;
    border-top: none;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table td {
    padding: 1rem 0.75rem;
    vertical-align: middle;
}

.badge.rounded-pill {
    font-weight: 500;
}

.card-header h5 {
    font-size: 1.1rem;
}
</style>

<script>
document.addEventListener('DOMContentLoaded', function() {
    // 添加表格行的点击效果
    const tableRows = document.querySelectorAll('.approval-row');

    tableRows.forEach(row => {
        const viewButton = row.querySelector('a.btn');
        if (viewButton) {
            row.style.cursor = 'pointer';
            row.addEventListener('click', function(e) {
                // 确保点击的不是按钮本身
                if (e.target.tagName !== 'A' && !e.target.closest('a')) {
                    viewButton.click();
                }
            });
        }
    });
});
</script>
{% endblock %}